<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Easy Login
 * @version 	1.0.0
 * @author 		kurosaki <kurosaki@gmail.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/**
 * @see Zmodule
 */

require_once(_PS_MODULE_DIR_.'zeasylogin/lib/zprofess/Zeasyloginmodule.php');

class ZEasyLoginConfig extends Zeasyloginmodule {	
	/**
	 * Destroy var config
	 * Configuration::deleteByName('ZCP_VERSION');
	 * @return boolean
	 */
 	public function destroyConfiguration () {
 		/*Genaral Tab*/
 		Configuration::deleteByName('ZTRANSITION_IN');
 		Configuration::deleteByName('ZTRANSITION_OUT');
 		Configuration::deleteByName('ZSPEED_IN');
 		Configuration::deleteByName('ZSPEED_OUT');
 		Configuration::deleteByName('ZOVERLAY_CLICK');
 		Configuration::deleteByName('ZCLOSE_BUTTON');
 		Configuration::deleteByName('ZBACKGROUND_COLOR');
 		Configuration::deleteByName('ZBORDER_COLOR');
 		Configuration::deleteByName('ZLINE_COLOR');
 		Configuration::deleteByName('ZOVERLAY_COLOR');
 		/*End Genaral Tab*/
 		return true;
	} 
    /**
     * Init var config
     * 
     * @return boolean
     */
	public function initConfiguration() {
		Configuration::updateValue('ZTRANSITION_IN',Tools::getValue('ZTRANSITION_IN','elastic'));
		Configuration::updateValue('ZTRANSITION_OUT',Tools::getValue('ZTRANSITION_OUT','elastic'));
		Configuration::updateValue('ZSPEED_IN',(int)Tools::getValue('ZSPEED_IN',300));
		Configuration::updateValue('ZSPEED_OUT',(int)Tools::getValue('ZSPEED_OUT',300));
		Configuration::updateValue('ZOVERLAY_CLICK',Tools::getValue('ZOVERLAY_CLICK', 1));
		Configuration::updateValue('ZCLOSE_BUTTON',Tools::getValue('ZCLOSE_BUTTON', 1));
		Configuration::updateValue('ZBORDER_COLOR',Tools::getValue('ZBORDER_COLOR', '#83888E'));
		Configuration::updateValue('ZBACKGROUND_COLOR',Tools::getValue('ZBACKGROUND_COLOR', '#E9E9E9'));
		Configuration::updateValue('ZLINE_COLOR',Tools::getValue('ZLINE_COLOR', '#000000'));
		Configuration::updateValue('ZOVERLAY_COLOR',Tools::getValue('ZOVERLAY_COLOR', '#777'));
		return true;
	}
	
	/**
	 * process date post from form config
	 * 
	 * @return void
	 */
	private function _postProcess()
	{
		$msg="";		
		if (Tools::isSubmit('submitGenaralTab')){
			Configuration::updateValue('ZTRANSITION_IN',Tools::getValue('ZTRANSITION_IN'));
			Configuration::updateValue('ZTRANSITION_OUT',Tools::getValue('ZTRANSITION_OUT'));
			Configuration::updateValue('ZSPEED_IN',(int)Tools::getValue('ZSPEED_IN',300));
			Configuration::updateValue('ZSPEED_OUT',(int)Tools::getValue('ZSPEED_OUT',300));
			Configuration::updateValue('ZOVERLAY_CLICK',Tools::getValue('ZOVERLAY_CLICK'));
			Configuration::updateValue('ZCLOSE_BUTTON',Tools::getValue('ZCLOSE_BUTTON'));
			Configuration::updateValue('ZBORDER_COLOR',Tools::getValue('ZBORDER_COLOR'));
			Configuration::updateValue('ZBACKGROUND_COLOR',Tools::getValue('ZBACKGROUND_COLOR'));
			Configuration::updateValue('ZLINE_COLOR',Tools::getValue('ZLINE_COLOR'));
			Configuration::updateValue('ZOVERLAY_COLOR',Tools::getValue('ZOVERLAY_COLOR'));
			
			$msg = $this->displayConfirmation('Settings configuration successful ');
		}
		echo $msg;
	}
	
	/*
	 * Display configuration page of module.
	 * 
	 * @return string html
	 */
	public function getContent() 
	{
		$this->_postProcess();
		return '<h2>'.$this->displayName.'</h2>'.$this->_displayForm();
	}
	
	/**
	 * display Form Config (All tab)
	 * 
     * @return string html
	 */
	protected function _displayFormConfig()
	{
		global $cookie,$currentIndex;

		$this->_html .= '
		
		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<fieldset>
				<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
				<fieldset style="float:left;width:400px;margin-right:5px;">
					<legend>'.$this->l('Popup fancybox').'</legend>';
		$arrTransition = array('none', 'fade', 'elastic'); 	
		$this->_html .= $this->addElement('select',array ('label'=>'Transition In','name'=>'ZTRANSITION_IN', 'note'=>'', 'value'=>'ZTRANSITION_IN', 'values'=>$arrTransition));
		$this->_html .= $this->addElement('select',array ('label'=>'Transition Out','name'=>'ZTRANSITION_OUT', 'note'=>'', 'value'=>'ZTRANSITION_OUT', 'values'=>$arrTransition));
		$this->_html .= $this->addElement('text',array ('label'=>'Speed In','name'=>'ZSPEED_IN', 'note'=>'','size'=>'10', 'value'=>'ZSPEED_IN'));
		$this->_html .= $this->addElement('text',array ('label'=>'Speed Out','name'=>'ZSPEED_OUT', 'note'=>'','size'=>'10', 'value'=>'ZSPEED_OUT'));
		$this->_html .= $this->addElement('yesno',array ('label'=>'Hide On Overlay Click','name'=>'ZOVERLAY_CLICK', 'note'=>'', 'value'=>'ZOVERLAY_CLICK'));
		$this->_html .= $this->addElement('yesno',array ('label'=>'Show Close Button','name'=>'ZCLOSE_BUTTON', 'note'=>'', 'value'=>'ZCLOSE_BUTTON'));
		$this->_html .= '
				</fieldset>
				<fieldset style="float:right;width:400px;">
				<script type="text/javascript" src="'._PS_JS_DIR_.'/jquery/jquery-colorpicker.js"></script>
					<legend>'.$this->l('Style Form').'</legend>';
		$this->_html .= $this->addElement('color',array ('label'=>'Border-color','name'=>'ZBORDER_COLOR', 'note'=>'', 'value'=>'ZBORDER_COLOR'));
		$this->_html .= $this->addElement('color',array ('label'=>'Background-color','name'=>'ZBACKGROUND_COLOR', 'note'=>'', 'value'=>'ZBACKGROUND_COLOR'));
		$this->_html .= $this->addElement('color',array ('label'=>'Line-color','name'=>'ZLINE_COLOR', 'note'=>'', 'value'=>'ZLINE_COLOR'));
		$this->_html .= $this->addElement('color',array ('label'=>'Overlay-color','name'=>'ZOVERLAY_COLOR', 'note'=>'', 'value'=>'ZOVERLAY_COLOR'));
		$this->_html .= '
				</fieldset>';
		$this->_html .= '
				<div class="clear"></div>
				<hr class="clear">
				<center><input type="submit" name="submitGenaralTab" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>
		<div class="clear" style="height:20px;" ></div>';

		
	}
	
	/**
	 * Display form General Settings
	 * 
	 * @return string html
	 */
	private function _displayFormGeneral()
	{
		return '';
	}
	
}